package com.iflytek.web.filter;


import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * 会拦截所有的请求，包含(前端的html/jsp/css/js/png/jpg等等文件)
 * 如果前端html出现乱码。解决：把前端html编码格式改为gbk即可。
 */
@WebFilter(filterName = "encodingFilter", urlPatterns = "/*")
public class EncodingFilter implements Filter {

    @Override
    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {


        // 能够直接设置编码
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");

        //之后放行
        chain.doFilter(request, response);

    }

    public void init(FilterConfig fConfig) throws ServletException {
    }

}
